<?php

namespace  Aitels\Foundation\Annotation;


class Annotation
{
    public const NAME = '';

    protected function isJson($value)
    {
        json_decode($value, true);
        return json_last_error() === JSON_ERROR_NONE;
    }

    protected function parseJson($value)
    {
        $arr = json_decode($value, true);
        if (json_last_error() !== JSON_ERROR_NONE)
            throw new \Exception('Json decode failed ');
        else
            return $arr;
    }

    protected function extractToParts($str)
    {
        $str = trim($str);
        $match = [];
        preg_match_all('/[a-zA-Z_\-0-9\.]+((=[\"\'][^\"]+[\"\'])|(=[\S]+))?/', $str, $match);

        foreach ($match[0] as &$part) {
            $part = str_replace(['"', "'"], ['', ''], $part);
        }

        return $match[0];
    }


}